package main

import (
	"bytes"
	"strconv"
)

func main() {
	println(countAndSay(5))
}

func countAndSay(n int) (res string) {
	res = "1"
	for i := 1; i < n; i++ {
		tmpStr := res
		res = ""
		n := len(tmpStr)
		str := bytes.Buffer{}
		for start, end := 0, 0; start < n; start = end {
			for ; end < n && tmpStr[end] == tmpStr[start]; end++ {
			}
			str.WriteString(strconv.Itoa(end - start))
			str.WriteByte(tmpStr[start])

		}
		res = str.String()
	}
	return
}
